<template>
	<view class="select-user-card-wrapper">

		<view class="user-card" :class="{'active': item.j_id == selectedUserCard.j_id}"
			v-for="(item, index) in userCardList" :key="index" @click="selectCard(item)">
			<p>{{item.names}}</p>
			<p>健康卡ID: {{item.numcard}}</p>
		</view>

		<button type="primary" class="up-button" @click="next">下一步</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userCardList: [],
				formData: {},
				selectedUserCard: {
					names: ''
				}
			}
		},
		onLoad(option) {
			this.formData = option.formData
			this.api_cardlist()
		},
		methods: {
			next() {
				if (this.selectedUserCard.names == '') {
					uni.showToast({
						title: '请先选择就诊人',
						icon: 'none'
					})
				}
				uni.navigateTo({
					url: '/pages/onlinePrescribe/selectDepartment?formData=' + this.formData + '&j_id=' + this
						.selectedUserCard.j_id
				})
			},

			selectCard(item) {
				this.selectedUserCard = item
			},

			api_cardlist() {
				let openid = uni.getStorageSync('openid')
				this.$app._post_form("entry/wxapp/apipatient.cardlist", {
					'openid': openid
				}, (res) => {
					if (res.status === 1) {
						this.userCardList = res.data
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.select-user-card-wrapper {
		width: 100%;
		height: 100%;
		padding: 15px;
		box-sizing: border-box;

		.user-card {
			padding: 10px;
			background-color: #fff;
			border-radius: 6px;
			margin-bottom: 10px;

			&.active {
				background-color: #41C177;
				color: #fff;
			}
		}
	}
</style>